// 学生获取自己的培养计划

import axios from "axios";

export default function (params) {
    return axios({
        method: "get",
        url: "/api/students/trainingPlan",
        params,
        header: {
            Authorization: localStorage.getItem("Authorization")
        }
    }).then(response => {
        // 对数据做预处理，添加key
        let trainingPlans = response.data.trainingPlans;
        for (let i = 0; i < trainingPlans.length; i++) {
            trainingPlans[i].key = i;
        }
        return {
            result: true,
            name: response.data.name,
            trainingPlans: response.data.trainingPlans
        }
    }).catch(error => {
        return {
            result: false,
            msg: error.response.data.msg
        }
    })
}


// 更新培养计划
export function updateTrainingPlans(majorId, gradeId, trainingPlans, method) {
    return axios({
        method: method,
        url: "/api/students/trainingPlans",
        data: {
            majorId, gradeId, trainingPlans
        },
        header: {
            Authorization: localStorage.getItem("Authorization")
        }
    }).then(response => {
        return {
            result: true,
            data: response.data
        }
    }).catch(error =>{
        return {
            result: false,
            msg: error.response.data.msg
        }
    })
}